Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DPE-4683] Typed configuration #337

Merged
merged 17 commits into from
Aug 27, 2024
Merged

[DPE-4683] Typed configuration #337

merged 17 commits into from
Aug 27, 2024

Conversation

dragomirp
Copy link
Contributor

@dragomirp dragomirp commented Aug 21, 2024

  • Bump libs
  • Add pydantic vaildation
  • Move sockets to accessible directories

Boilerplate for #343

Copy link

codecov bot commented Aug 21, 2024

Codecov Report

Attention: Patch coverage is 75.94937% with 19 lines in your changes missing coverage. Please review.

Project coverage is 73.35%. Comparing base (f96e625) to head (a0adef9).
Report is 4 commits behind head on main.

Files Patch % Lines
src/charm.py 72.72% 9 Missing and 3 partials ⚠️
src/relations/pgbouncer_provider.py 37.50% 3 Missing and 2 partials ⚠️
src/relations/db.py 60.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #337      +/-   ##
==========================================
+ Coverage   73.09%   73.35%   +0.25%     
==========================================
  Files           8        9       +1     
  Lines        1286     1321      +35     
  Branches      224      227       +3     
==========================================
+ Hits          940      969      +29     
- Misses        267      272       +5     
- Partials       79       80       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@dragomirp dragomirp changed the title [DPE-4683] Provide socket in URI [DPE-4683] Expose socket connection Aug 22, 2024
@dragomirp dragomirp changed the title [DPE-4683] Expose socket connection [DPE-4683] Typed configuration Aug 22, 2024
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly copypaste from PG VM charm

@@ -143,7 +143,7 @@ async def test_remove_tls(ops_test: OpsTest, pgb_charm_jammy):
@pytest.mark.group(1)
async def test_remove_vip(ops_test: OpsTest):
async with ops_test.fast_forward():
await ops_test.model.applications[PGB].set_config({"vip": ""})
await ops_test.model.applications[PGB].reset_config(["vip"])
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Empty string will no longer pass the address validation.

Comment on lines +136 to +146
try:
self._grafana_agent = COSAgentProvider(
self,
metrics_endpoints=[
{"path": "/metrics", "port": self.config.metrics_port},
],
log_slots=[f"{PGBOUNCER_SNAP_NAME}:logs"],
refresh_events=[self.on.config_changed],
)
except ValueError:
logger.warning("Unable to set COS agent, invalid config")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Data will be validated the first time we access self.config

metrics_port: PositiveInt
vip: Optional[IPvAnyAddress]
pool_mode: Literal["session", "transaction", "statement"]
max_db_connections: conint(ge=0)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 is unlimited db conns.

Comment on lines +331 to +332
if not self.charm.configuration_check():
return
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function will be rerun on config change

@@ -229,7 +227,7 @@ def _on_relation_broken(self, event: RelationBrokenEvent) -> None:

def update_connection_info(self, relation):
"""Updates client-facing relation information."""
if not self.charm.unit.is_leader():
if not self.charm.unit.is_leader() or not self.charm.configuration_check():
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function will be rerun on config change.

Comment on lines +780 to +782
if not self.configuration_check():
return

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

File will be rerendered on config change.

@dragomirp dragomirp marked this pull request as ready for review August 23, 2024 02:55
@dragomirp dragomirp requested review from a team, taurus-forever, marceloneppel and lucasgameiroborges and removed request for a team August 23, 2024 02:55
Copy link
Member

@marceloneppel marceloneppel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Copy link
Contributor

@taurus-forever taurus-forever left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Insane work done. Thank you!

LGTM, one question about write perms inside. If you really need it - LGTM.


# Make a directory for each service to store configs.
for service_id in self.service_ids:
os.makedirs(f"{app_conf_dir}/{INSTANCE_DIR}{service_id}", 0o700, exist_ok=True)
os.chown(f"{app_conf_dir}/{INSTANCE_DIR}{service_id}", pg_user.pw_uid, pg_user.pw_gid)
os.makedirs(f"{app_run_dir}/{INSTANCE_DIR}{service_id}", 0o777, exist_ok=True)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we limit it to read for others? Do they need a write capabilities?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clients could be other users, so we can't limit the reads for sure, they should be able to traverse to the socket. Writes we most probably don't need, but let's tweak it in the follow up PRs.

@dragomirp dragomirp merged commit e646caa into main Aug 27, 2024
58 checks passed
@dragomirp dragomirp deleted the dpe-4683-socket branch August 27, 2024 12:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants